﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Microsoft.DirectX;
using SimulationPresenter.Presentation.Primitives;

namespace SimulationPresenter.Simulation.Primitive
{
    internal class RidigMesh : ISimulationPrimitive, IRidig
    {
        //TODO: Change this class name - makes no sense - Ridig would be much better
        public RidigMesh()
        {
            Transformation = Matrix.Identity;
        }

        public string Name
        {
            get;
            set;
        }

        public Matrix Transformation
        { 
            get;
            set;
        }

        private IPresentationPrimitive bodyShape;
        public IPresentationPrimitive BodyShape
        {
            set
            {
                bodyShape = value;
            }
        }

        public ISimulationPrimitive PutOrUpdate(SimulationEnvironment enviroment)
        {
            if (null == bodyShape)
            {
                throw new DataException("Body shape is empty. Shape is obligatory to simulate RidigMesh.");
            }

            Transformation = enviroment.Core.CreateMesh(Name, 
                                        bodyShape.GetPositions(), bodyShape.Indices,
                                        Transformation);
            return this;
        }
    }
}
